-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use tray_icon
crate for better tray icon support
#288
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for converting it! Didn't know you were working on it, ping me in such cases so we don't do the same work twice (I didn't start on this yet, don't worry).
Looks like a much nicer library than betrayer
, wondering why it wasn't used in the first place 🤔
This will need to be tested on Windows and Linux, you'll also have to update documentation on required dependencies since it seems like we have some added in here. For Linux we should be using libayatana-appindicator3-dev
as a dependency.
One thing that will likely make this unusable/unacceptable for Linux is that it is based on GTK3, not GTK4.
GTK3 is legacy and we don't compile/include it on Windows or macOS.
I think it'll work for Windows and macOS since it is not GTK3 that is used there to drive tray icon (hence the question why atk
was installed on macOS).
On Linux https://github.com/iovxw/ksni was suggested in tauri-apps/tray-icon#107 and probably worth exploring (betrayer
for example doesn't work on my system, but ksni
seems to support more protocols and should start working).
Assuming we go with 2 libraries, the tray icon creation should probably be wrapped into a platform-specific struct that will handle the initialization and that we can store in the App
instance.
Overall this is a good start, but needs more work and more testing before we can merge it.
P.S. Tray icons are a mess on Linux:
src/frontend.rs
Outdated
let image = image::load_from_memory(ICON) | ||
.expect("Statically correct image; qed") | ||
.to_rgba8(); | ||
|
||
let (width, height) = image.dimensions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variables will be unused on Windows and cause clippy warnings. They should be grouped with tray icon construction using let tray_icon = {};
.
Also you can use image::load_from_memory_with_format(ICON, image::ImageFormat::Png)
as more concrete method and you can use image.width()
instead of extracting separate variables first.
src/frontend.rs
Outdated
.with_menu(std::boxed::Box::new( | ||
Menu::with_items(&[ | ||
&MenuItem::with_id( | ||
TRAY_ICON_MENU_OPEN_ID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you don't really need to assign ID explicitly, just create menu item with ::new()
and then store ID in a variable with menu_item.id()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tray icon initialization and receiving menu events are in different scopes with the latest refactoring. do you think I should just save the IDs and expose a method to retrieve them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do. I basically expect something like platform-specific constructors or even functions that take Sender
as an argument and return opaque TrayIcon
instance back that frontend will need to keep around for tray icon to continue functioning.
src/frontend.rs
Outdated
Menu::with_items(&[ | ||
&MenuItem::with_id( | ||
TRAY_ICON_MENU_OPEN_ID, | ||
T.tray_icon_open().to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoudn't need an allocation, try this:
T.tray_icon_open().to_string(), | |
&T.tray_icon_open(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried this, but it raises a compile error due to trait bound of AsrRef<str>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be de-referenced first: &*T.tray_icon_open()
2209bac
to
fbb7b7c
Compare
fbb7b7c
to
56d7e33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a step in the right direction, but a bit overengineered and Linux support is not implemented fully
src/frontend.rs
Outdated
Menu::with_items(&[ | ||
&MenuItem::with_id( | ||
TRAY_ICON_MENU_OPEN_ID, | ||
T.tray_icon_open().to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be de-referenced first: &*T.tray_icon_open()
33ff0a4
to
acea905
Compare
I haven't yet tested this on non-MacOS Linux machine but I think I resolved all the comments code-wise @nazar-pc |
I did some refactoring, fixed some issues and added single left click handling. Tested on Windows and Ubuntu and confirmed that it works there at least. @dastansam can you confirm it still works on macOS as expected? |
Still doesn't work on my Linux due to lack of legacy icons support in the library, but it is not worse than before, so not a blocker. |
7d71043
to
92c964c
Compare
|
It closes the app. It was working like this until you changed it, so I restored it back to what it was. Renaming is possible, but we'll have to update a bunch of translations in that case. I'll take care of it tomorrow alongside with one more improvement. |
closes #222
tested on MacOS
Screen.Recording.2024-08-12.at.10.49.15.mov